package com.itheima.tliaswebmanagement;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.junit.jupiter.api.Test;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class testGenJwt {
    @Test
    public void test1() {
        Map<String, Object> claims = new HashMap<>();
        claims.put("id", 1);
        claims.put("username", "itheima");
        String jwt = Jwts.builder().signWith(SignatureAlgorithm.HS256, "xixi")
                .addClaims(claims)
                .setExpiration(new Date(System.currentTimeMillis()+1000*60*60))
                .compact();
        System.out.println(jwt);
    }

    @Test
    public void test2(){
        Claims claims = Jwts.parser().setSigningKey("xixi")
                .parseClaimsJws("eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJpdGhlaW1hIiwiZXhwIjoxNzU5OTgyODIzfQ.2_hM1CWvXwcMnZl3D-NEv0X3eKaOzm22fnetBSIR_mk")
                .getBody();
        System.out.println(claims);

    }
}
